package cn.hallele.leinsteining.ms.auditcenter.service.log.service;

import cn.hallele.leinsteining.ms.auditcenter.service.log.bo.LogBO;
import cn.hallele.leinsteining.ms.auditcenter.service.log.das.LogBODas;
import cn.hallele.leinsteining.ms.support.starter.components.audit.io.ApiLogIO;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * LogService
 *
 * @author anle5
 * @since 2024/7/28 22:30
 */
@Slf4j
@Service
public class ManageLogService {
    @Autowired
    private LogBODas logBODas;

    public void saveLog(ApiLogIO apiLogIO) {
        LogBO logBO = logBODas.convert(apiLogIO);

        Object response = apiLogIO.getResponse();
        Object request = apiLogIO.getRequest();
        logBO.setRequest(JSONUtil.toJsonStr(request));
        logBO.setResponse(JSONUtil.toJsonStr(response));
        logBO.setCreateBy(11111111111L);
        logBO.setInitiator(11111111111L);
        logBO.setTranceId("asdsadasdasdsadsad");
        LogBO result = logBODas.saveOne(logBO);
        log.info("Audit log [{}-{}] save successful", result.getId(), result.getApiId());
    }
}
